package cn.z2huo.demo.redis.spring.service.impl;

import cn.z2huo.demo.model.dataobject.user.UserDO;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.stereotype.Service;

/**
 * <p>
 *
 * @author z2huo
 */
@Service
public class RedisTemplateSetServiceImpl {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Qualifier("redisTemplate")
    @Autowired
    private RedisTemplate<String, UserDO> userRedisTemplate;

    private SetOperations<String, String> setOperations;

    private SetOperations<String, UserDO> userSetOperations;

    @PostConstruct
    private void init() {
        setOperations = redisTemplate.opsForSet();
        userSetOperations = userRedisTemplate.opsForSet();
    }

    public void set(String key, UserDO value) {
        userRedisTemplate.opsForSet().add(key, value);
    }

    public void set(String key, String value) {
        redisTemplate.opsForSet().add(key, value);
    }

}
